package com.dg11185.nearshop.net.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.dg11185.nearshop.net.entity.MerchantItem;

public class GetFavorListResponse {

	public NetStatus status = null;

    public String total = null;

    public List<MerchantItem> merchants = null;
	
    public GetFavorListResponse() {
        merchants = new ArrayList<MerchantItem>();
    }
    
    public void parseJson(String response) {
    	
    	 try {
             JSONObject jsonObject = new JSONObject(response);
             total = jsonObject.optString("total");
             status = NetStatus.getStatus(jsonObject.optString("status"));

             if (!jsonObject.isNull("merchantList")) {
                 JSONArray merchantArray = jsonObject.optJSONArray("merchantList");

                 for (int a = 0; a < merchantArray.length(); a++) {
                     MerchantItem merchant = new MerchantItem();
                     merchant.parseEntity(merchantArray.getJSONObject(a));
                     merchants.add(merchant);
                 }
             }
         } catch (JSONException e) {
             e.printStackTrace();
         }
    }
}
